var nowDate = getDay(0);
var pandianid = GetQueryString('pandianid');
var shopcode = sessionStorage.getItem("shopcode");
var shopname = sessionStorage.getItem("shopname");
var userId = sessionStorage.getItem("userId");
//StoreNO店号  userId 操作人
$(document).ready(function(){
	window.addEventListener('pageshow', function(e) {
	    if (e.persisted) {
	        window.location.reload();
	    }else{
//			Statue = decodeURI(decodeURI(Statue))
			$('#nameh').text(shopcode+"."+shopname);
//			$('#Statueh').append(Statue);
			$('#name').text(sessionStorage.getItem("name"));
		}
	    getPandianJianchaZicai();
	});
});
//获取盘点检查信息
function getPandianJianchaZicai(){
	showloading();
	$.ajax({  
		url: "../pandianevery/getPandianJianchaZicai"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"pandianid":pandianid,'shopcode':shopcode}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
			try {
				if(res.success){
					var data = res.data[0];
					$('#Statueh').text(data.flagname);
					addClick(data.flag);
				}else{
					$('#Statueh').text('未开始');
//					layer.msg(res.message);
					addClick(0)
				}
			} catch (e) {
				console.log(e)
			} finally{
				hideloading();
			}
			
		}
	});
}
function addClick(flag){
	if(flag == '1'){
		$('#pdupdate').on('click',function(){
			pdeidt();
		});
		$('#pdsearch').on('click',function(){
			pdsearch();
		});
		$('#pdcancel').on('click',function(){
			pdcancel();
		});
		$('#pdfinish').on('click',function(){
			pdfinish();
		});
		$('#pdstart').off('click');
		$('#pdupdate,#pdsearch,#pdcancel,#pdfinish').addClass('bg_orange');
		$('#pdstart').removeClass('bg_orange').css('background-color','#BEBEBE');
	}else if(flag == '2'){
		$('#pdsearch').on('click',function(){
			pdsearch();
		});
		$('#pdupdate,#pdstart,#pdcancel,#pdfinish').off('click');
		$('#pdupdate,#pdstart,#pdcancel,#pdfinish').removeClass('bg_orange').css('background-color','#BEBEBE');
		$('#pdsearch').addClass('bg_orange');
	}else if(flag == '3'){
		$('#pdstart').on('click',function(){
			pdeidt();
		});
		$('#pdupdate,#pdsearch,#pdcancel,#pdfinish').off('click');
		$('#pdupdate,#pdsearch,#pdcancel,#pdfinish').removeClass('bg_orange').css('background-color','#BEBEBE');
		$('#pdstart').addClass('bg_orange');
	}else{
		$('#pdstart').on('click',function(){
			pdeidt();
		});
		$('#pdupdate,#pdsearch,#pdcancel,#pdfinish').off('click');
		$('#pdupdate,#pdsearch,#pdcancel,#pdfinish').removeClass('bg_orange').css('background-color','#BEBEBE');
		$('#pdstart').addClass('bg_orange');
	}
}
function pdfinish(){

	 dd.device.notification.confirm({
	    message: "确认完成吗",
	    title: "提示",
	    buttonLabels: ['是', '否'],
	    onSuccess : function(result) {
	        if(result.buttonIndex==0){
						$.ajax({
						url: "../pandianevery/editPandianJianchaZicaiFlag"
						,type:'post'
						,data:JSON.stringify({"pandianid":pandianid,"flag":2})
						,contentType: "application/json; charset=utf-8"
						,dataType:'json'
						,success: function(res){
							if(res.success){
								goback();
							}
						}
					});
			}
	    },
	    onFail : function(err) {}
	});


}

function pdeidt(){
	window.location.href = "toPandian_zicai?pandianid="+pandianid;
}
function pdsearch(){
	window.location.href = "toPandian_zicai_chayi?pandianid="+pandianid;//此处拼接内容
}
function pdcancel(){
   dd.device.notification.confirm({
    message: "确认撤销吗",
    title: "提示",
    buttonLabels: ['是', '否'],
    onSuccess : function(result) {
		if(result.buttonIndex==0){
			$.ajax({
				url: "../pandianevery/editPandianJianchaZicaiFlag"
				,type:'post'
				,data:JSON.stringify({"pandianid":pandianid,"flag":3})
				,contentType: "application/json; charset=utf-8"
				,dataType:'json'
				,success: function(res){
					if(res.success){
						goback();
					}
				}
		    });
			
		}
    },
    onFail : function(err) {}
});


}
function goback(){
	window.location.href='toJiancha_index_list?pandianid='+pandianid;
}
